<?php

namespace App\Http\Controllers\Excel\Extensions;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Maatwebsite\Excel\Concerns\Exportable;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
use Maatwebsite\Excel\Concerns\FromArray;
use Maatwebsite\Excel\Concerns\WithDrawings;
use PhpOffice\PhpSpreadsheet\Worksheet\Drawing;
use Maatwebsite\Excel\Concerns\WithHeadings;
class Exporter implements FromArray, ShouldAutoSize, WithDrawings,WithHeadings
{
    protected $invoices;
    public function __construct(array $invoices)
    {
        $this->invoices = $invoices;
    }

    use Exportable;

    public function array(): array
    {
        return $this->invoices;
    }

    public function drawings()
    {
        foreach ($this->invoices as $k => $v) {
            ${'drawing' . $k} = new Drawing();
            ${'drawing' . $k}->setName('头像');
            ${'drawing' . $k}->setDescription('头像');
            //图片路径
            ${'drawing' . $k}->setPath(storage_path('app/'.$v[0]));
            ${'drawing' . $k}->setHeight(90);
            //设置图片列
            ${'drawing' . $k}->setCoordinates('A' . $k);
            $result[] = ${'drawing' . $k};
        }
        return $result;
    }
    public function headings(): array
    {
        return [
            '图片','钻类型(方/圆)','数量','短边','长边','面积','是否定制'
        ];
    }


}
